package com.example.sort;

import java.util.Arrays;

/**
 * @author zhanpengguo
 * @date 2019-07-31 10:53
 */
public class XiEr {

    public static Integer[] sort(Integer[] arrays) {
        Integer[] ints = Arrays.copyOf(arrays, arrays.length);
        int len = ints.length;
        for (double gap = Math.floor(len / 2); gap >= 0; gap = Math.floor(gap / 2)) {
            int gap1 = Double.valueOf(gap).intValue();
            for (int i = gap1; i < len; i++) {
                int j = i;
                int current = ints[j];
                while (j - gap1 > 0 && ints[j - gap1] > current) {
                    ints[j] = ints[j - gap1];
                    j = j - gap1;
                }
                ints[j] = current;
            }
        }
        return ints;
    }

}
